/**
 * \file Page.h
 * \brief VM page.
 * \author Corey Tabaka
 */

/*
   Copyright 2007 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include <ktypes.h>
#include <Reference.h>
#include <Queue.h>
#include <vm/Cache.h>

#ifndef __KERNEL_PAGE_H__
#define __KERNEL_PAGE_H__

enum {
	PAGE_STATE_ACTIVE=0,
	PAGE_STATE_INACTIVE,
	PAGE_STATE_BUSY,
	PAGE_STATE_MODIFIED,
	PAGE_STATE_FREE,
	PAGE_STATE_CLEAR,
	PAGE_STATE_WIRED,
	PAGE_STATE_UNUSED,
};

class Page {
	friend class AddressSpace;
	friend class Region;
	friend class Cache;
	friend class Memory;
	
	protected:
	
	uint32 page;
	offset_t offset;
	uint32 state;
	uint32 flags;
	
	QList queueNode; // entry in the queue this page resides in
	QList cacheNode; // entry in the cache this page resides in
	
	RefCache cache;
	
	public:
	
	Page(uint32 page, uint32 state);
	Page(uint32 page, uint32 state, offset_t offset);
	
	uint32 getPage(void);
	offset_t getOffset(void);
	uint32 getState(void);
	void setState(uint32 state);
	
	static Page *lookup(uint32 page);
	static void dump(void);
};

#endif
